package acm.pta;

import java.util.Scanner;

public class G {
    static int[] weight={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    static char[] keys={'1','0','X','9','8','7','6','5','4','3','2'};
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count = sc.nextInt();
        sc.nextLine();
        StringBuilder str=new StringBuilder();
        while (count-- > 0) {
            String s = sc.nextLine();
            if (!verify(s.replace("X",":"))) {
                str.append(s+"\n");
            }
        }
        System.out.print(str.length()==0?"All passed\n":str);
    }
    public static boolean verify(String s){
        char[] chars = s.toCharArray();
        chars[chars.length-1]=chars[chars.length-1]==':'?'X':chars[chars.length-1];
        int sum=0;
        for (int i = 0; i < weight.length; i++) {
            sum+=(chars[i]-'0')*weight[i];
        }
        return keys[sum%keys.length]==chars[chars.length-1];
    }
}
